import logging
import random

from tools.page import page_get


def 判断是否存在滑块验证码(iframe):
    count = 0
    while True:
        iframe2 = iframe.get_frame('#baxia-dialog-content', timeout=60)
        logging.info('出现滑块验证码')
        if count == 3:
            return '滑块验证码超过3次验证失败'
        btn_slide = iframe2.ele('#nc_1_n1z')
        iframe2.actions.hold(btn_slide)
        iframe2.actions.move(300, 25, 2)
        iframe2.wait(1)
        if iframe2('#`nc_1_refresh1`', timeout=1):
            count += 1
            logging.info('滑块验证码验证失败')
            iframe2('#`nc_1_refresh1`').click()
            iframe2.wait(3)
            btn_slide = iframe2.ele('#nc_1_n1z')
        if not btn_slide.states.is_displayed:
            logging.info('滑块验证码验证成功')
            break

# page = page_get()
# iframe = page.get_frame('#iframe-gyl_print_service', timeout=60)
# 判断是否存在滑块验证码(iframe)
